package niuke;

import java.util.Scanner;

public class 买苹果 {
    static int n;
    static int min = 99999999;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        if(n%2 == 1){
            System.out.println(-1);
            return;
        }
        dfs(0,0);
        if(min == 99999999){
            min=-1;
        }
        System.out.println(min);
    }

    public static void dfs(int sum,int count){
        if(sum>n || count > min){
            return;
        }
        if(sum == n && count<min){
            min = count;
            return;
        }
        dfs(sum+6,count+1);
        dfs(sum+8,count+1);
    }
}
